package com.waldamartin.android.mobileapplicationspairsapp.control;

import java.util.ArrayList;

import com.waldamartin.android.mobileapplicationspairsapp.R;
import com.waldamartin.android.mobileapplicationspairsapp.model.Game;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Class to deal games overview
 * 
 * @author Martin
 */
public class GamesListViewAdapter extends BaseAdapter
{
	private ArrayList<Game> arrayList;
	
	/**
	 * Set associated list
	 * 
	 * @param gamesList
	 */
	public GamesListViewAdapter(ArrayList<Game> gamesList)
	{
		this.arrayList = gamesList;
	}

	@Override
	public int getCount()
	{
		return arrayList.size();
	}

	@Override
	public Game getItem(int position)
	{
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return (long)position;
	}

	@SuppressLint({ "ViewHolder", "InflateParams" })
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		// Set entry
		convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.game_list_row,null);
		
		ImageView imageView_iamge = (ImageView)convertView.findViewById(R.id.entry_image);
		imageView_iamge.setImageResource(this.arrayList.get(position).getSet().get(0));
		
		TextView textView_name = (TextView)convertView.findViewById(R.id.entry_name);
		textView_name.setText(this.arrayList.get(position).getName());
		
		TextView textView_details = (TextView)convertView.findViewById(R.id.entry_details);
		if (this.arrayList.get(position).getLastTimePlayed() != null)
		{
			textView_details.setText(convertView.getResources().getString(R.string.lastPlayed) + "\n" + this.arrayList.get(position).getLastTimePlayed());
		}
		else
		{
			textView_details.setText(convertView.getResources().getString(R.string.notJet));
		}
		return convertView;
	}	

}
